﻿using EFUtil.Migrations;
using EFUtil.Migrations.SqlServer;
using System.Data.Entity.Infrastructure;

namespace EFUtil.TestApplication
{
    public class ProductInitializer : MigratingInitializer<ProductsContext>
    {
        public ProductInitializer(INewVersionProvider<ProductsContext> versionProivider)
            : base(versionProivider)
        {

        }

        protected override void BeforeMigration(ProductsContext context)
        {
            var adapter = context as IObjectContextAdapter;
            if (context.Database.Exists())
                adapter.ObjectContext.ExecuteStoreCommand("Update Products Set ProductNumber = ProductNumber + '1'");
        }

        protected override void AfterMigration(ProductsContext context)
        {
            var adapter = context as IObjectContextAdapter;
            adapter.ObjectContext.ExecuteStoreCommand("Update Products Set ProductName = ProductNumber + ' name'");
        }
    }
}
